<?php
// 本类由系统自动生成，仅供测试用途
namespace Admin\Controller;
use Think\Controller;
class SinglerateController extends Controller {
    /**
     * 客户信息页面渲染
     * @return [type] [description]
     */
    public function cityquery(){
        session('orders',null);
        $this->display();
    }
    /**
     * 城市过单页面渲染
     */
    public function overmonorate(){
        session('orders',null);
        $this->display();
    }
    /**
     * 城市逾期页面渲染
     */
    public function cityoverdue(){
        session('orders',null);
        $this->display();
    }
    /**
     * 城市风控明细页面渲染
     */
    public function cityrisk(){
        session('orders',null);
        $this->display();
    }
    /**
     * 时间推算
     */
    public function TimePublic(){
        $curry = date('Y', time());
        $currm = date('m', time());
        $y = date('Y', 1517363215);
        $m = date('m', 1517363215);
        $curr = ($curry * 12 + $currm) - ($y * 12 + $m);
        $times = [1, $curr+1];
        return $times;
    }
    /**
     * 过单订单查询
     * @param  [type] $CSarr    [查询出的城市经理]
     * @param  [type] $timeaarr [推算出的时间数组]
     * @return [type]           [description]
     */
    public function findVal($CSarr,$timeaarr){
        $canalRecord= M('wayuser_operation');
        $orderoperat= M('order_operation');
        $canaltotal = M('wayuser');
        $city       = M('city');
        $admin      = M('admin');
        $order      = M('order');
        foreach ($CSarr as $key => $value) {
            $adminname   = $admin->where("status <> 1 and pid =".$value['id'])->select();
            $adminnames   = $admin->where("1=1 and pid =".$value['id'])->select();
            $admisz      = $admin->where("position = 4 and provinceid =".$value['provinceid'])->find();
            $admin_Gw_id = '"'.implode('","', array_column($adminnames, 'id')).'"';
            $CSarr[$key]['wayinc'] = $canaltotal->where(" 1=1 and status = 2 and admin_id in (".$admin_Gw_id.")")->count();
            $CSarr[$key]['inc'] = count($adminname);
            $CSarr[$key]['szusernum'] =  $admisz['usernum'];
            $CSarr[$key]['szname']    =  $admisz['name'];
            $dataarr = $this->tooSingleRate($adminname,$timeaarr);
            $CSarr[$key]['guodanarr'] = $dataarr;
            
        }
        return $CSarr;
    }
    /**
     * 计算过单率
     */
    public function tooSingleRate($adminname,$timeaarr){
        $canalRecord= M('wayuser_operation');
        $orderoperat= M('order_operation');
        $canaltotal = M('wayuser');
        $city       = M('city');
        $admin      = M('admin');
        $order      = M('order');
        $admin_Gw    = '"'.implode('","', array_column($adminname, 'usernum')).'"';
        $operation   = "1=1 and status=0 and usernum in (".$admin_Gw.")";
        $ordercity   = $orderoperat->where($operation)->select();
        $admin_order = '"'.implode('","', array_column($ordercity, 'orderid')).'"';
        $admin_ope   = "1=1 and status <> 0  and orderid in (".$admin_order.")";
        $ordercityarr= $orderoperat->where($admin_ope)->select();
        $dataarr     = [];
        foreach ($timeaarr as $k => $va) {
            $data['ordercoun']     = 0;//循环月过单
            $data['ordermonth']    = 0;//循环月总单
            $dacity['totalorder']  = 0;//失败订单
            $dacity['tooorder']    = 0;//总过单
            foreach ($ordercityarr as $ok => $ov) {
                $ordertime = date("Y-m",$ov['create_time']);
                if($ov['status'] == 2 && $ordertime == $va){
                    $data['ordercoun'] += 1;//通过
                }elseif($ov['status'] == -1 && $ordertime == $va){
                    $data['ordermonth'] += 1;//失败
                }
                if(intval($ov['status']) ==2){
                    $dacity['tooorder'] += 1;//总通过
                }elseif(intval($ov['status']) ==-1){
                     $dacity['totalorder'] += 1;//总失败
                }
            }
            $data['ordermon'] = $data['ordercoun'].":".($data['ordermonth']+$data['ordercoun']);
            $data['orderrate']  = round($data['ordercoun']/($data['ordermonth']+$data['ordercoun'])*100,2);
            $dataarr[] = $data;
        }
        $dacity['tooordercount'] = $dacity['tooorder'].":".($dacity['tooorder']+$dacity['totalorder']);
        $dacity['tooorderccount']  = round($dacity['tooorder']/($dacity['tooorder']+$dacity['totalorder'])*100,2);
        $dataarr[] = $dacity;
        return $dataarr;
    }
    /**
     * 过单
     */
    public function Slerate($data=false){
        $city       = M('city');
        $admincity  = M('admin');
        $adminorder = M('order');
        $canaltotal = M('wayuser');
        $canalRecord= M('wayuser_operation');
        if(!$data['risktype']){
            $data = I('post.');
        }
        if(!$data['start'] && !$data['end']){
            $datatime = $this->TimePublic();
            $data['start'] = $datatime[0];
            $data['end']   = $datatime[1];
        }
        $datetime = $this->getDates($data['start'],$data['end']);
        $condition  = "1=1";
        $adminjudge = "1=1";
        if(!$data['start'] && !$data['end']){
            $datatime = $this->TimePublic();
            $data['start'] = $datatime[0];
            $data['end']   = $datatime[1];
        }
        if($data['cityname']){
        	$condition  .= " and type = 2";
        	$condition  .= ' and (name like "%'.$data['cityname'].'%")';
       		$rescity = $city->where($condition)->find();
            $adminres= $admincity->where('test_sign =0 and position = 3 and cityid ='.$rescity['id'])->select();
            $cityGW   = $this->findVal($adminres,$datetime);
        }elseif($data['typelv'] == "toorate"){
        	if($data['provinceid'] && empty($data['cityid'])){
                $adminres= $admincity->where('test_sign =0 and position = 3 and provinceid ='.$data['provinceid'])->select();
                $cityGW   = $this->findVal($adminres,$datetime);
        	}elseif($data['provinceid'] && $data['cityid']){
                $adminres= $admincity->where('test_sign =0 and position = 3 and cityid ='.$data['cityid'])->select();
                $cityGW   = $this->findVal($adminres,$datetime);
        	}else{
                $adminres= $admincity->where('test_sign =0 and position = 3')->select();
                $cityGW   = $this->findVal($adminres,$datetime);
            }
  
        }
        $resarr = [];
        foreach ($cityGW as $ke => $value) {
            $value['citycount'] = $value['inc'];
            $value['waycount']  = $value['wayinc'];
            $value['provanem']  = $city->where(array('id'=>$value['provinceid']))->find()['name'];//省
            $value['cityname']  = $city->where(array('id'=>$value['cityid']))->find()['name'];//市
            $value['start']     = $data['start'];
            $value['end']       = $data['end'];
            foreach ($value['guodanarr'] as $ko => $va) {
                if(intval($va['tooorderccount']) > intval($data['signrate']) &&  intval($va['tooorderccount']) <= intval($data['signendrate']) || intval($va['orderrate']) > intval($data['signrate']) &&  intval($va['orderrate']) <= intval($data['signendrate'])){
                    $value['typesign'] = "red";
                }
                if(intval($va['ordercoun']) >= intval($data['startrate']) &&  intval($va['orderrate']) <= intval($data['endrate']) ||intval($va['tooorderccount']) >= intval($data['startrate']) &&  intval($va['tooorderccount']) <= intval($data['endrate']) ){
                    if(!in_array($value,$resarr)){
                        $resarr[] = $value;
                    }
                }

            }
        }
        if($data['risktype'] == "riskkong"){
            return $resarr;
        }else{
            session('orders', base64_encode(json_encode($resarr)));
            $this->ajaxReturn(array('resdata'=>$resarr));
        }
    }
    
    /**
     * 时间转换
     * @param  [type] $start [description]
     * @param  [type] $end   [description]
     * @return [type]        [description]
     */
    public function getDates($start = 1, $end = 12)
    {
        $date = [];
        $m = date('m', time());
        $y = date('Y', time());
        $m = $m - $start + 1;
        if ($m <= 0) {
            $m = 12 + $m;
            $y = $y - 1;
        }
        $currtime = strtotime($this -> get_y_m_d($y, $m));
        $count = $end - $start;
        for ($i = 0; $i <= $count; $i++) {
            $date[$i] = date('Y-m', $currtime);
            $d = date('d', $currtime);
            $time = $currtime - (60*60*24*$d);
            $currtime = $time;
        }
        return $date;
    }
    /**
     * 时间转换
     * @param  [type] $start [description]
     * @param  [type] $end   [description]
     * @return [type]        [description]
     */
    public function get_y_m_d($y, $m)
    {
        if( in_array($m , array(1, 3, 5, 7, 8, 01, 03, 05, 07, 10, 12)))
        {
            // $text = $year.'年的'.$month.'月有31天';
            $text = '31';
        }
        elseif( $m == 2 )
        {
            if ( $y % 400 == 0  || ($y % 4 == 0 && $y % 100 !== 0) )        //判断是否是闰年
            {
                // $text = $year.'年的'.$month.'月有29天';
                $text = '29';
            }
            else{
                // $text = $year.'年的'.$month.'月有28天';
                $text = '28';
            }
        }
        else{

            // $text = $year.'年的'.$month.'月有30天';
            $text = '30';
        }
        return $y.'-'.$m.'-'.$text;
    }

    /**
     * 逾期订单比
     * @param  [type] $CSarr    [城市经理数组]
     * @param  [type] $timeaarr [时间数组]
     * @return [type]           [Array]
     */
	public function findOrderOverdue($CSarr,$timeaarr){
        $jdcordermonthpay = M('order_month_pay');
        $canalRecord= M('wayuser_operation');
        $orderoperat= M('order_operation');
        $canaltotal = M('wayuser');
        $city       = M('city');
        $admin      = M('admin');
        $order      = M('order');
        foreach ($CSarr as $key => $value) {
            $adminname   = $admin->where("status <> 1 and pid =".$value['id'])->select();
            $adminnames  = $admin->where("1=1 and pid =".$value['id'])->select();
            $admin_Gw_id = '"'.implode('","', array_column($adminnames, 'id')).'"';
            $CSarr[$key]['wayinc'] = $canaltotal->where(" 1=1 and status = 2 and admin_id in (".$admin_Gw_id.")")->count();
            $CSarr[$key]['inc'] = count($adminname);
            $SZarr =  $admin->where("position = 4 and provinceid =".$value['provinceid'])->find();
            $CSarr[$key]['szusernum'] =  $SZarr['usernum'];
            $CSarr[$key]['szname']    =  $SZarr['name'];
            $resorder = $this->overdueRate($adminname,$timeaarr);
            $CSarr[$key]['orderarr'] = $resorder;
            
        }
        return $CSarr;
	}
    /**
     * 计算逾期率
     */
    public function overdueRate($adminname,$timeaarr){
        $jdcordermonthpay = M('order_month_pay');
        $canalRecord= M('wayuser_operation');
        $orderoperat= M('order_operation');
        $canaltotal = M('wayuser');
        $city       = M('city');
        $admin      = M('admin');
        $order      = M('order');
        $admin_Gw    = '"'.implode('","', array_column($adminname, 'usernum')).'"';
        $operation   = "1=1 and status=0 and usernum in (".$admin_Gw.")";
        $ordercity   = $orderoperat->where($operation)->select();
        $orderdata   = '"'.implode('","', array_column($ordercity, 'orderid')).'"';
        $monthpaydata= $jdcordermonthpay->where('orderid in ('.$orderdata.')')->select();
        $dataarr     = [];
        foreach ($timeaarr as $ke => $value) {
            $data['overdue']      = 0;//当月逾期单数
            $data['ordercount']   = 0;//当月总单比
            $data['overdueorder'] = 0;//总单比率
            $datacount['overduecount'] = 0;//总逾期单数
            $datacount['orderoverducount'] = 0;//总单数
            foreach ($ordercity as $k=> $v) {
                $typestatus  = $jdcordermonthpay->where("overdue_status = 1 and orderid = ".$v['orderid'])->find();
                if($typestatus){
                    $datacount['overduecount'] += 1;//总逾期单数
                }
                if($jdcordermonthpay->where("orderid = ".$v['orderid'])->find()){
                    $datacount['orderoverducount'] +=1;
                }
             
                foreach ($monthpaydata as $keys => $values) {
                        $monthtime = date('Y-m',$values['pay_time']);
                            // var_dump($monthtime);
                        if($monthtime == $value && $values['orderid'] == $v['orderid'] && $values['overdue_status'] == 1){
                            $data['overdue'] += 1;
                        
                        }
                        if($monthtime == $value && $values['orderid'] == $v['orderid']){
                            $data['ordercount'] += 1;
                        }
                }
                
            }

            $data['overdueorder'] = $data['overdue'].':'.$data['ordercount'];
            $data['overduerate']  = round($data['overdue']/($data['ordercount'])*100,2);
            $dataarr[] = $data;
        }
        $datacount['overduecountorder'] = $datacount['overduecount'].':'.$datacount['orderoverducount'];
        $datacount['overduecountrate']  = round($datacount['overduecount']/($datacount['orderoverducount'])*100,2);
        $dataarr[] = $datacount;
        return $dataarr;
    }

    /**
     * 逾期率
     */
	public function OverdueOrder($data=false){
		$city       = M('city');
        $admincity  = M('admin');
        $adminorder = M('order');
        if(!$data['risktype']){
            $data = I('post.');
        }
        if(!$data['start'] && !$data['end']){
            $datatime = $this->TimePublic();
            $data['start'] = $datatime[0];
            $data['end']   = $datatime[1];
        }
        $datetime = $this->getDates($data['start'],$data['end']);
        $condition  = "1=1";
        $adminjudge = "1=1";
        if($data['cityname']){
            $data['startrate'] = "0";//开始百分比过滤
            $data['endrate'] = "100";//结束百分比过滤
            $condition  .= " and type = 2";
            $condition  .= ' and (name like "%'.$data['cityname'].'%")';
            $rescity = $city->where($condition)->find();
            $adminres= $admincity->where('test_sign =0 and position = 3 and cityid ='.$rescity['id'])->select();
            $cityGW   = $this->findOrderOverdue($adminres,$datetime);
            
        }elseif($data['typelv'] == "toorate"){
            if($data['provinceid'] && empty($data['cityid'])){
                $adminres= $admincity->where('test_sign =0 and position = 3 and provinceid ='.$data['provinceid'])->select();
                $cityGW   = $this->findOrderOverdue($adminres,$datetime);
            }elseif($data['provinceid'] && $data['cityid']){
                $adminres= $admincity->where('test_sign =0 and position = 3 and cityid ='.$data['cityid'])->select();
                $cityGW   = $this->findOrderOverdue($adminres,$datetime);
            }else{
                $adminres= $admincity->where('test_sign =0 and position = 3')->select();
                $cityGW   = $this->findOrderOverdue($adminres,$datetime);
            }
  
        }
        $resarr = [];
        foreach ($cityGW as $ke => $value) {
            $value['citycount'] = $value['inc'];
            $value['waycount']  = $value['wayinc'];
            $value['provanem']  = $city->where(array('id'=>$value['provinceid']))->find()['name'];//省
            $value['cityname']  = $city->where(array('id'=>$value['cityid']))->find()['name'];//市
            $value['start']     = $data['start'];
            $value['end']       = $data['end'];
            foreach ($value['orderarr'] as $k => $va) {
                if($data['signrate'] && $data['signendrate']){
                        if(intval($data['signrate'] < intval($va['overduerate'])) &&  intval($va['overduerate']) <= intval($data['signendrate']) || intval($va['overduecountrate']) >= intval($data['signrate']) &&  intval($va['overduecountrate']) <= intval($data['signendrate'])){
                            $value['typesign'] = "red";
                        }
                }
                
            }
            foreach ($value['orderarr'] as $ko => $va) {
                if(intval($va['overduerate']) >= intval($data['startrate']) &&  intval($va['overduerate']) <= intval($data['endrate']) ||intval($va['overduecountrate']) >= intval($data['startrate']) &&  intval($va['overduecountrate']) <= intval($data['endrate'])){
                    if(!in_array($value,$resarr)){
                        $resarr[] = $value;
                    }
                }
                
                
            }
        }
        if($data['risktype'] == "riskkong"){
            return $resarr;
        }else{
            session('orders', base64_encode(json_encode($resarr)));
            $this->ajaxReturn(array('resdata'=>$resarr));
        }
	}
    /**
     * 城市联动下拉
     */
    public function region() {
        $city_db = D('city');
        $data = $city_db->CityGetAll();
        echo json_encode(['success'=>'OK','data'=>$data]);
    }
    /**
     * 客户信息查询
     */
    public function CustomerList($datatype=false){
        $data = I('request.');
        $user       = M('user');
        $city       = M('city');
        $admincity  = M('admin');
        $adminorder = M('order');
        $canaltotal = M('wayuser');
        $canalRecord= M('wayuser_operation');
        $ordertion  = M('order_operation');
        $omonthpay  = M('order_month_pay');
        $carprice   = M('car_price');
        $rescity = [];
        $condition = '1=1 ';
        if($data['username']){
            $condition  .= '  and (fullanme like "%'.$data['username'].'%")';
            $condition  .= ' or (tel like "%'.$data['username'].'%")';
            $condition  .= ' and jdc_order.status >= 3 and jdc_order.status <> 7';
            $rescity = $user->field('*,jdc_user.address as addssre')->join('jdc_order on jdc_order.uid=jdc_user.id')->where($condition)->select();
            if(!$rescity){
                $this->ajaxReturn(['success'=>"ERROR","msg"=>"未找到到用户"]);
            }
        }elseif($data['provinceid'] || $data['status']){
            $condition  .= ' and jdc_order.status >= 3 and jdc_order.status <> 7';
            $resarr = $user->field('*,jdc_user.address as addssre')->where($condition)->join('jdc_order on jdc_order.uid=jdc_user.id')->select();
            if($data['provinceid']){
                if($data['provinceid'] && $data['cityid']){
                    foreach ($resarr as $k=> $v) {
                        if($v['cityid'] == $data['cityid']){

                            $thpay = $omonthpay->where(array('uid'=>$v['uid']))->select();
                            $userids = explode(',',implode(',', array_column($thpay, 'overdue_status')));
                            if(!in_array('1',$userids) && $data['status'] == "2"){
                                $rescity[] = $v;
                            }elseif(in_array('1',$userids) && $data['status'] == "1"){
                                $rescity[] = $v;
                            }elseif($data['status'] == ""){
                                $rescity[] = $v;  
                            }
                        }
                    }  
                }elseif($data['provinceid']){
                    foreach ($resarr as $key => $value) {

                        if($value['provinceid'] == $data['provinceid']){
                            $thpay = $omonthpay->where(array('uid'=>$value['uid']))->select();
                            $userids = explode(',',implode(',', array_column($thpay, 'overdue_status')));
                            if(!in_array('1',$userids) && $data['status'] == "2"){
                                $rescity[] = $value;
                            }elseif(in_array('1',$userids) && $data['status'] == "1"){
                                $rescity[] = $value;
                            }elseif($data['status'] == ""){
                                $rescity[] = $value;  
                            }
                        }
                    }
                }
            }else{
                foreach ($resarr as $key => $value) {
                    $thpay = $omonthpay->where(array('uid'=>$value['uid']))->select();
                    $userids = explode(',',implode(',', array_column($thpay, 'overdue_status')));
                    if(!in_array('1',$userids) && $data['status'] == "2"){
                        $rescity[] = $value;
                    }elseif(in_array('1',$userids) && $data['status'] == "1"){
                        $rescity[] = $value;
                    }
                }
            }
        }else{
            $condition  .= ' and jdc_order.status >= 3 and jdc_order.status <> 7';
            $rescity = $user->field('*,jdc_user.address as addssre')->where($condition)->join('jdc_order on jdc_order.uid=jdc_user.id')->select();
        }
        foreach ($rescity as $key => $value) {
            $provincename = $city->where(" id = ".$value['provinceid'])->find()['name'];//省
            $cityname     = $city->where(" id = ".$value['cityid'])->find()['name'];//市
            $tionlist     = $ordertion->where("status=0 and orderid = ".$value['orderid'])->find();
            $adminname    = $admincity->where(array("usernum"=>$tionlist['usernum']))->find();//顾问姓名
            $versionname  = $carprice->where(array("version"=>$value['price_version'],'carnum'=>$value['carnum']))->find()['jdc_price'];//整台价
            $thpay = $omonthpay->where(array('uid'=>$value['uid'],'status'=>1))->sum('money');
            if(!$thpay){
                $thpay = "--";
            }
            $thpaytype = $omonthpay->where(array('uid'=>$value['uid'],'status'=>0))->find();
            if($thpaytype){
                $rescity[$key]['thpaytype'] = "是";
            }else{
                $rescity[$key]['thpaytype'] = "否";
            }
            $rescity[$key]['provincename'] = $provincename;
            $rescity[$key]['cityname']  = $cityname;
            $rescity[$key]['gwusernum'] = $adminname['usernum'];
            $rescity[$key]['gwname']    = $adminname['name'];
            $rescity[$key]['jdc_price'] = $versionname;
            $rescity[$key]['thpay']     = $thpay;
            $rescity[$key]["identify_url"]    = serializeMysql($value["identify_url"],1);
            $rescity[$key]["driver_url"]      = serializeMysql($value["driver_url"],1);
            $rescity[$key]["workproof_url"]   = serializeMysql($value["workproof_url"],1);
            $rescity[$key]["bankflow_url"]    = serializeMysql($value["bankflow_url"],1);
            $rescity[$key]["creditreport_url"]= serializeMysql($value["creditreport_url"],1);
            $rescity[$key]["otherdata_url"]   = serializeMysql($value["otherdata_url"],1);
        }
        session('orders', base64_encode(json_encode($rescity)));
        if($datatype){
            return $rescity;
        }else{
            $this->ajaxReturn(array('resdata'=>$rescity));
        }
    }
    /**
     * 循环订单
     * @param  [type] $arr      [description]
     * @param  [type] $orderarr [description]
     * @param  [type] $cityid   [description]
     * @return [type]           [description]
     */
    public function findOrder($arr,$orderarr,$cityid){
        $dataarr   = []; 
        $operation = M('order_operation');
        foreach ($arr as $key => $value) {
            $data['ordercoun'] = 0;//循环月过单
            $data['ordermonth'] = 0;//循环月总单
            $dacity['totalorder']  =0;//失败订单
            $dacity['tooorder']  =0;//总过单
            foreach ($orderarr as $k => $v) {
                $operarr= $operation->where('orderid ='.$v['orderid'])->select();
                foreach ($operarr as $ke => $val) {
                    $ordertime = date("Y-m",$val['create_time']);
                    if($v['cityid'] == $cityid  && intval($val['status']) == 2 && $ordertime == $value){
                        $data['ordercoun'] += 1;//通过
                    }
                    if($v['cityid'] == $cityid  && intval($val['status']) ==-1 && $ordertime == $value){
                         $data['ordermonth'] += 1;//失败
                    }

                    if($v['cityid'] == $cityid  && intval($val['status']) ==2){
                        $dacity['tooorder'] += 1;//总通过
                    }
                    if($v['cityid'] == $cityid  && intval($val['status']) ==-1){
                         $dacity['totalorder'] += 1;//总失败
                    }
                }
            }
            $data['ordermon'] = $data['ordercoun'].":".($data['ordermonth']+$data['ordercoun']);
            $data['orderrate']  = round($data['ordercoun']/($data['ordermonth']+$data['ordercoun'])*100,2);
            $dataarr[] = $data;
        }
       
        $dacity['tooordercount'] = $dacity['tooorder'].":".($dacity['tooorder']+$dacity['totalorder']);
        $dacity['tooorderccount']  = round($dacity['tooorder']/($dacity['tooorder']+$dacity['totalorder'])*100,2);
        $dataarr[] = $dacity;
        return $dataarr;
    }
    
    /**
     * 城市风控订单详情查询
     */
    public function findOrderDatalis($data,$timearr){
        $jdcordermonthpay = M('order_month_pay');
        $canalRecord= M('wayuser_operation');
        $orderoperat= M('order_operation');
        $canaltotal = M('wayuser');
        $city       = M('city');
        $admin      = M('admin');
        $order      = M('order');
        $adminname   = $admin->where("pid =".$data['id'])->select();
        $admin_Gw_id = '"'.implode('","', array_column($adminname, 'id')).'"';
        $data['wayinc'] = $canaltotal->where(" 1=1 and status = 2 and admin_id in (".$admin_Gw_id.")")->count();
        $data['inc'] = count($adminname);
        $SZarr       =  $admin->where("provinceid =".$data['provinceid'])->find();
        $data['szusernum'] =  $SZarr['usernum'];
        $data['szname']    =  $SZarr['name'];  
    }
    /**
     * 城市风控明细查询
     */
    public function cityriskkong(){
        $data = I('post.');
        $city       = M('city');
        $admincity  = M('admin');
        $adminorder = M('order');
        $canaltotal = M('wayuser');
        if(!$data['risktype']){
            $data = I('post.');
        }
        if(!$data['start'] && !$data['end']){
            $datatime = $this->TimePublic();
            $data['start'] = $datatime[0];
            $data['end']   = $datatime[1];
        }
        if(!$data['overend'] && !$data['overstart']){
            $datatime = $this->TimePublic();
            $data['overstart'] = $datatime[0];
            $data['overend']   = $datatime[1];
        }
        $datetime    = $this->getDates($data['start'],$data['end']);
        $ovedatetime = $this->getDates($data['overstart'],$data['overend']);
        $condition   = "1=1";
        $adminjudge  = "1=1";
        if($data['cityname']){
            if($data['typeurl']){
                $condition = " id = ".$data['cityname'];
                $adminres  = $admincity->where($condition)->select();
            }else{
                $condition  .= " and type = 2";
                $condition  .= ' and (name like "%'.$data['cityname'].'%")';
                $rescity = $city->where($condition)->find();
                $adminres= $admincity->where('position = 3 and cityid ='.$rescity['id'])->select();
            }
        }elseif($data['typelv'] == "toorate"){
            if($data['provinceid'] && empty($data['cityid'])){
                $adminres= $admincity->where('position = 3 and provinceid ='.$data['provinceid'])->select();
            }elseif($data['provinceid'] && $data['cityid']){
                $adminres= $admincity->where('position = 3 and cityid ='.$data['cityid'])->select();
            }else{
                
                $adminres= $admincity->where('position = 3')->select();
            }
  
        }
        foreach ($adminres as $key => $value) {
            $SZarr       =  $admincity->where("position = 4 and provinceid =".$value['provinceid'])->find();
            $adminres[$key]['szusernum'] =  $SZarr['usernum'];
            $adminres[$key]['szname']    =  $SZarr['name'];
            $adminres[$key]['provanem']  = $city->where(array('id'=>$value['provinceid']))->find()['name'];//省
            $adminres[$key]['cityname']  = $city->where(array('id'=>$value['cityid']))->find()['name'];//市
            $adminnames   = $admincity->where("1=1 and pid =".$value['id'])->select();
            $adminname   = $admincity->where("status <> 1 and  pid =".$value['id'])->select();
            $admin_Gw_id = '"'.implode('","', array_column($adminnames, 'id')).'"';
            $adminres[$key]['waycount'] = $canaltotal->where(" 1=1 and status = 2 and admin_id in (".$admin_Gw_id.")")->count();
            $adminres[$key]['citycount'] = count($adminname);
            $resover = $this->overdueRate($adminname,$ovedatetime);//逾期
            $restoo  = $this->tooSingleRate($adminname,$datetime);//过单
            $adminres[$key]['tooarr']= $restoo;
            $adminres[$key]['orderarr']= $resover;
            $adminres[$key]['start']= $data['start'];
            $adminres[$key]['end']= $data['end'];
            $adminres[$key]['overstart']= $data['overstart'];
            $adminres[$key]['overend']= $data['overend'];
        }
        foreach ($adminres as $key => $value) {
            $advarrlv = [];//逾期
            $tooarrlv = [];//过单
           foreach ($value['orderarr'] as $k => $va) {
                // print_r($data);
                // print_r($value['orderarr']);die;
                if($data['overstartcolor2'] && $data['overendcolor2']){
                    if(intval($va['overduerate']) >= intval($data['overstartcolor2']) &&  intval($va['overduerate']) <= intval($data['overstartcolor2']) || intval($va['overduecountrate']) >= intval($data['overstartcolor2']) &&  intval($va['overduecountrate']) <= intval($data['overendcolor2'])){
                        $adminres[$key]['typesign'] = "red";
                    }
                }
                if(intval($va['overduerate']) >= intval($data['overstartrate']) &&  intval($va['overduerate']) <= intval($data['overendrate']) || intval($va['overduecountrate']) >= intval($data['overstartrate']) &&  intval($va['overduecountrate']) <= intval($data['overendrate'])){
                    if(!in_array($va,$advarrlv)){
                        $advarrlv[] = $va;
                    }
                }
            }
            foreach ($value['tooarr'] as $k => $va) {
                if($data['overstartcolor1'] && $data['overendcolor1']){
                    if(intval($va['orderrate']) >= intval($data['overstartcolor1']) &&  intval($va['orderrate']) <= intval($data['overendcolor1']) || intval($va['tooorderccount']) >= intval($data['overendcolor1']) &&  intval($va['tooorderccount']) <= intval($data['overendcolor1'])){
                        $adminres[$key]['typesign'] = "red";
                    }
                }
                if(intval($va['orderrate']) >= intval($data['startrate']) &&  intval($va['orderrate']) <= intval($data['endrate']) || intval($va['tooorderccount']) >= intval($data['startrate']) &&  intval($va['tooorderccount']) <= intval($data['endrate'])){
                    if(!in_array($va,$tooarrlv)){
                        $tooarrlv[] = $va;
                    }
                }
            }
            
            if(empty($tooarrlv)){
                unset($adminres[$key]['tooarr']);
            }
            if(empty($advarrlv)){
                unset($adminres[$key]['orderarr']);
            }
        }
        session('orders', base64_encode(json_encode($adminres)));
        $this->ajaxReturn(array('resdata'=>$adminres));
    }
    /**
     * [ExportExcelYear 客户]
     */
    public function  ExportExcelYear(){
        $jdcorderoperation      = M('order_operation');
        $city       = M('city');
        $orderM     = M('order');
        $admincity  = M('admin');
        $canaltotal = M('wayuser');
        $canalRecord= M('wayuser_operation');
        $ordertion  = M('order_operation');
        $omonthpay  = M('order_month_pay');
        $carprice   = M('car_price');
        $datastatus = I("post.status");
        $arrarray   = I("post.arrarray");
        if($datastatus == 5){
            $rescity = json_decode(base64_decode(session('orders')),true);
        }else{
            $times = $this -> get_d_m($datastatus);
            $orderidarr = $jdcorderoperation->where('status = 3')->select();
            $orderarr = [];
            foreach ($orderidarr as $key => $value) {
                $opertime = date("Y-m",$value['create_time']);
                if(in_array($opertime,$times)){
                   $orderarr[] = $value;
                }
            }
            $cityarr  = $city->select();
            $order_id   = '"'.implode('","', array_column($orderarr, 'orderid')).'"';
            $condition  .= ' 1=1 and jdc_order.orderid in ('.$order_id.')';
            $rescity = $orderM->field('*,jdc_order.address as addssre')->join('jdc_user on jdc_user.id=jdc_order.uid')->where($condition)->select();
        }
        $indexi = 1;
        $datas=[];
        foreach ($rescity as $key => $value) {
            if($datastatus != 5){
                $tionlist     = $ordertion->where("status=0 and orderid = ".$value['orderid'])->find();
                $adminname    = $admincity->where(array("usernum"=>$tionlist['usernum']))->find();//顾问姓名
                $provincename = $city->where(" id = ".$value['provinceid'])->find()['name'];//省
                $cityname     = $city->where(" id = ".$value['cityid'])->find()['name'];//市
                $carpice      = $carprice->where(array("version"=>$value['price_version'],'carnum'=>$value['carnum']))->find()['jdc_price'];//整台价
                $thpay = $omonthpay->where(array('uid'=>$value['uid'],'status'=>1))->sum('money');
                $value = $this->KefuGuoLv($value,false);
            }else{
                $provincename = $value['provincename'];
                $cityname = $value['cityname'];
                $adminname['name'] = $value['gwname'];
                $adminname['usernum'] = $value['gwusernum'];
                $carpice = $value['jdc_price'];
                $thpay   = $value['thpay'];
                $value = $this->KefuGuoLv($value,true);
            }
            $data = array();
            $data[]=$indexi++;
            $data[]=$value['fullanme'];
            $data[]=$value['sex'];
            $data[]=$value['tel'];
            $data[]=$value['birthday'];
            $data[]=$value['marriage'];
            $data[]=$value['addssre'];
            $data[]=$value['liveaddress'];
            $data[]=$value['companyaddress'];
            $data[]=$value['housingnature'];
            $data[]=$value['identify_url'];
            $data[]=$value['banknum'];
            $data[]=$value['bank'];
            $data[]=$value['banker'];
            $data[]=$value['usertype'];
            $data[]=$value['creditreport_url'];
            $data[]=$value['workunit'];
            $data[]=$value['income'];
            $data[]=$value['creditcard'];
            $data[]=$value['borrowing'];
            $data[]="无";
            $data[]=$value['bankflow_url'];
            $data[]=$value['workproof_url'];
            $data[]=$value['creditreport_url'];
            $data[]=$value['otherdata_url'];
            $data[]=$value['contacts_name'].'/'.$value['contacts_phone'].'/'.$value['contacts_bearing'];
            $data[]=$value['contacts_user_name'].'/'.$value['contacts_phone_tel'].'/'.$value['contacts_sip_bearing'];
            $data[]=$adminname['name'];
            $data[]=$adminname['usernum'];
            $data[]=$value['waynum'];
            $data[]=$provincename;
            $data[]=$cityname;
            $data[]="是";
            $data[]=$value['status'];
            $data[]=$value['orderid'];
            $data[]=$carpice;
            $data[]=$thpay;
            $datas[] = $data;
        }
        $title = [
                '序号',                    
                '客户姓名',                     
                '性别',
                '联系方式',
                '出生日期',
                '婚姻状况',
                '户籍地址',
                '常住地址',
                '公司地址',
                '个人住房性质',
                '身份证核对',
                '银行卡号',
                '银行名称',
                '银行账户名',
                '客户类型',
                '驾驶证核对',
                '单位名称',
                '个人税前收入',
                '信用卡情况',
                '银行借款情况',
                '非银行拖欠情况',
                '银行流水核对',
                '户口本/工作证明',
                '征信报告/社保缴费记录/公积金缴费记录',
                '补填资料',//===
                '紧急联系人',
                '紧急联系人',
                '顾问姓名',
                '员工岗位号',
                '渠道编号',
                '所属省份',
                '所属城市',
                '是否有订单',
                '订单状态',
                '订单编号',
                '车辆整台价',
                '当前累计付款',
            ];
        if(isset($arrarray) && $datastatus == 5 && $arrarray){
            foreach ($datas as $key => $value) {
                foreach ($value as $k => $v) {
                    if(!in_array($k,$arrarray)){
                        unset($datas[$key][$k]);
                    }
                }
            }
            foreach ($title as $key => $value) {
                if(!in_array($key,$arrarray)){
                    unset($title[$key]);
                }
            }
        }
        $filename_n = time();
        $filename_exce = "sheet";
        // 生成Excel并返回文件名称
        $filename = ExportExcelTable($title,$datas,$filename_exce,$filename_n,'./Public/Uploads/ChannelCount/');
        $path = 'http://'.$_SERVER['SERVER_NAME'].substr($filename, 1, strlen($filename));
        $this -> ajaxReturn(['success'=>'OK','path' => $path], 'JSON');
        //exit(json_encode(['success'=>'OK','filename'=>$filename_n,'message'=>$filename_n.'导出成功！']));
    }
    /**
     * [ExportExcelSeason 逾期]
     */
    public function  ExportExcelSeason(){
        $datastatus = I("post.status");
        $arrarray   = I("post.arrarray");
        $city       = M('city');
        $admincity  = M('admin');
        $adminorder = M('order');
        if($datastatus == 5){
            $cityGW = json_decode(base64_decode(session('orders')),true);
            if($cityGW){
                $times = $this->getDates($cityGW[0]['start'],$cityGW[0]['end']);
            }
        }else{
            $times = $this -> get_d_m($datastatus);
            $adminres= $admincity->where('test_sign =0 and position = 3')->select();
            $cityGW   = $this->findOrderOverdue($adminres,$times);
        }
        $title = [
                  "序号",
                  "城市名称",
                  "所属省份",
                  "GW在职总数",
                  "城市渠道激活数",
                  "CS姓名",
                  "CS岗位号",
                  "SZ姓名",
                  "SZ岗位号",
                  "总逾期数",
                  "总逾期比",
                  "总逾期率",
                 ];
        
        foreach ($times as $key => $value) {
            array_push($title,$value.'逾期数');
            array_push($title,$value.'逾期比');
            array_push($title,$value.'逾期率');
        }
        $indexi = 0;
        $datas = [];
        foreach ($cityGW as $key => $value) {
            $data   = [];
            $data[] = $indexi++;
            if($datastatus != 5){
                $data[] = $city->where(array('id'=>$value['cityid']))->find()['name'];//市
                $data[] = $city->where(array('id'=>$value['provinceid']))->find()['name'];//省
            }else{
                $data[] = $value['provanem'];
                $data[] = $value['cityname'];
            }
            $data[] = $value['inc'];
            $data[] = $value['wayinc'];
            $data[] = $value['name'];
            $data[] = $value['usernum'];
            $data[] = $value['szname'];
            $data[] = $value['szusernum'];
            foreach ($value['orderarr'] as $k => $v) {
                if($v['overduecount'] || $v['overduecountorder'] || $v['overduecountrate']){
                    $data[] = $v['overduecount'];
                    $data[] = $v['overduecountorder'];
                    $data[] = $v['overduecountrate'];
                }
            }
            foreach ($value['orderarr'] as $k => $v) {
                if($v['overdue'] || $v['overdueorder'] || $v['overduerate']){
                    $data[] = $v['overdue'];
                    $data[] = $v['overdueorder'];
                    $data[] = $v['overduerate'];
                }
            }
            $datas[] = $data;
        }
        if(isset($arrarray) && $datastatus == 5 && $arrarray){
            foreach ($datas as $key => $value) {
                foreach ($value as $k => $v) {
                    if(!in_array($k,$arrarray)){
                        unset($datas[$key][$k]);
                    }
                }
            }
            foreach ($title as $key => $value) {
                if(!in_array($key,$arrarray)){
                    unset($title[$key]);
                }
            }
        }

        $filename_n = time();
        $filename_exce = "sheet";
        // 生成Excel并返回文件名称
        $filename = ExportExcelTable($title,$datas,$filename_exce,$filename_n,'./Public/Uploads/ChannelCount/');
        $path = 'http://'.$_SERVER['SERVER_NAME'].substr($filename, 1, strlen($filename));
        $this -> ajaxReturn(['success'=>'OK','path' => $path], 'JSON');
        //exit(json_encode(['success'=>'OK','filename'=>$filename_n,'message'=>$filename_n.'导出成功！']));
    }

    /**
     * [ExportExcelSeason 过单]
     */
    public function  ExportExcelUpper(){
        $datastatus = I("post.status");
        $arrarray   = I("post.arrarray");
        $city       = M('city');
        $admincity  = M('admin');
        $adminorder = M('order');
        $adminres= $admincity->where('test_sign =0 and position = 3')->select();
        if($datastatus == 5){
            $cityGW = json_decode(base64_decode(session('orders')),true);
            if($cityGW){
                $times = $this->getDates($cityGW[0]['start'],$cityGW[0]['end']);
            }
        }else{
            $adminres= $admincity->where('test_sign =0 and position = 3')->select();
            $times = $this -> get_d_m($datastatus);
            $cityGW   = $this->findVal($adminres,$times);
        }           
        $title = [
                  "序号",
                  "城市名称",
                  "所属省份",
                  "GW在职总数",
                  "城市渠道激活数",
                  "CS姓名",
                  "CS岗位号",
                  "SZ姓名",
                  "SZ岗位号",
                  "总过单数",
                  "总过单比",
                  "总过单率",
                 ];
        
        foreach ($times as $key => $value) {
            array_push($title,$value.'过单数');
            array_push($title,$value.'过单比');
            array_push($title,$value.'过单率');
        }
        $datas = [];
        $indexi = 0;
        foreach ($cityGW as $key => $value) {
            $data = [];
            $data[] = $indexi++;
            if($datastatus != 5){
                $data[] = $city->where(array('id'=>$value['cityid']))->find()['name'];//市
                $data[] = $city->where(array('id'=>$value['provinceid']))->find()['name'];//省
            }else{
                $data[] = $value['provanem'];
                $data[] = $value['cityname'];
            }
            $data[] = $value['inc'];
            $data[] = $value['wayinc'];
            $data[] = $value['name'];
            $data[] = $value['usernum'];
            $data[] = $value['szname'];
            $data[] = $value['szusernum'];
            foreach ($value['guodanarr'] as $k => $v) {
                if($v['totalorder'] || $v['tooordercount'] || $v['tooorderccount']){
                    $data[] = $v['totalorder'];
                    $data[] = $v['tooordercount'];
                    $data[] = $v['tooorderccount'];
                }
            }
            foreach ($value['guodanarr'] as $k => $v) {
                if($v['ordercoun'] || $v['ordermon'] || $v['orderrate']){
                    $data[] = $v['ordercoun'];
                    $data[] = $v['ordermon'];
                    $data[] = $v['orderrate'];
                }
            }
            $datas[] = $data;
        }
        if(isset($arrarray) && $datastatus == 5 && $arrarray){
            foreach ($datas as $key => $value) {
                foreach ($value as $k => $v) {
                    if(!in_array($k,$arrarray)){
                        unset($datas[$key][$k]);
                    }
                }
            }
            foreach ($title as $key => $value) {
                if(!in_array($key,$arrarray)){
                    unset($title[$key]);
                }
            }
        }
        $filename_n = time();
        $filename_exce = "sheet";
        // 生成Excel并返回文件名称
        $filename = ExportExcelTable($title,$datas,$filename_exce,$filename_n,'./Public/Uploads/ChannelCount/');
        $path = 'http://'.$_SERVER['SERVER_NAME'].substr($filename, 1, strlen($filename));
        $this -> ajaxReturn(['success'=>'OK','path' => $path], 'JSON');
        // exit(json_encode(['success'=>'OK','filename'=>$filename_n,'message'=>$filename_n.'导出成功！']));  
    }
    /**
     * [ExportExcelSeason 风控明细]
     */
    public function  ExportExcelDetailed(){
        $datastatus = I('post.status');
        $arrarray = I('post.arrarray');
        $city       = M('city');
        $admincity  = M('admin');
        $adminorder = M('order');
        $canaltotal = M('wayuser');
        $adminres   = $admincity->where('test_sign = 0 and position = 3')->select();
        $datas  =[];
        $indexi = 0;
        $title = [
                  "序号",
                  "城市名称",
                  "所属省份",
                  "GW在职总数",
                  "城市渠道激活数",
                  "CS姓名",
                  "CS岗位号",
                  "SZ姓名",
                  "SZ岗位号",
                 ];
        array_push($title,'总过单数');
        array_push($title,'总过单比');
        array_push($title,'总过单率');
        if($datastatus == 5){
            $adminres = json_decode(base64_decode(session('orders')),true);
            $times1 = $this->getDates($adminres[0]['start'],$adminres[0]['end']);
            $times2 = $this->getDates($adminres[0]['overstart'],$adminres[0]['overend']);
            foreach ($times1 as $k => $v) {
                array_push($title,$v.'过单数');
                array_push($title,$v.'过单比');
                array_push($title,$v.'过单率');
            }
            array_push($title,'总逾期数');
            array_push($title,'总逾期比');
            array_push($title,'总逾期率');
            foreach ($times2 as $k => $v) {
                array_push($title,$v.'逾期数');
                array_push($title,$v.'逾期比');
                array_push($title,$v.'逾期率');
            }
        }else{
            $times      = $this -> get_d_m($datastatus);
            foreach ($times as $k => $v) {
                array_push($title,$v.'过单数');
                array_push($title,$v.'过单比');
                array_push($title,$v.'过单率');
            }
            array_push($title,'总逾期数');
            array_push($title,'总逾期比');
            array_push($title,'总逾期率');
            foreach ($times as $k => $v) {
                array_push($title,$v.'逾期数');
                array_push($title,$v.'逾期比');
                array_push($title,$v.'逾期率');
            }
        }

        foreach ($adminres as $key => $value) {
                if($datastatus == 5){
                    $SZarr['name']  = $value['szname'];
                    $SZarr['usernum']  = $value['szusernum'];
                    $provanem = $value['provanem'];
                    $cityname = $value['cityname'];
                    $citycount= $value['citycount'];
                    $waycount = $value['waycount'];
                    $resover  = $value['orderarr'];
                    $restoo   = $value['tooarr'];
                }else{
                    $adminname   = $admincity->where("status <> 1 and pid =".$value['id'])->select();
                    $admin_Gw_id = '"'.implode('","', array_column($adminname, 'id')).'"';
                    $SZarr       =  $admincity->where("provinceid =".$value['provinceid'])->find();
                    $provanem    = $city->where(array('id'=>$value['provinceid']))->find()['name'];//省
                    $cityname    = $city->where(array('id'=>$value['cityid']))->find()['name'];//市
                    $waycount    = $canaltotal->where(" 1=1 and status = 2 and admin_id in (".$admin_Gw_id.")")->count();
                    $citycount    = count($adminname);
                    $resover = $this->overdueRate($adminname,$times);//逾期
                    $restoo  = $this->tooSingleRate($adminname,$times);//过单
                }
                $data   = array();
                $data[] =  $indexi++;
                $data[] =  $cityname;
                $data[] =  $provanem;
                $data[] =  $citycount;
                $data[] =  $waycount;
                $data[] =  $value['name'];
                $data[] =  $value['usernum'];
                $data[] =  $SZarr['name'];
                $data[] =  $SZarr['usernum'];
                if($restoo){
                    foreach ($restoo as $k => $v) {
                        if($v['totalorder'] || $v['tooordercount'] || $v['tooorderccount']){
                            
                            $data[] = $v['totalorder'];
                            $data[] = $v['tooordercount'];
                            $data[] = $v['tooorderccount'];
                        }
                    }
                    foreach ($restoo as $k => $v) {
                        if($v['ordercoun'] || $v['ordermon'] || $v['orderrate']){
                            $data[] = $v['ordercoun'];
                            $data[] = $v['ordermon'];
                            $data[] = $v['orderrate'];
                        }
                    }
                }
                if($resover){
                    foreach ($resover as $k => $v) {
                        if($v['overduecount'] || $v['overduecountorder'] || $v['overduecountrate']){
                            $data[] = $v['overduecount'];
                            $data[] = $v['overduecountorder'];
                            $data[] = $v['overduecountrate'];
                        }
                    }
                    foreach ($resover as $k => $v) {
                        if($v['overdue'] || $v['overdueorder'] || $v['overduerate']){
                            $data[] = $v['overdue'];
                            $data[] = $v['overdueorder'];
                            $data[] = $v['overduerate'];
                        }
                    }
                }
                $datas[] = $data;
            }
        if(isset($arrarray) && $datastatus == 5 && $arrarray){
            foreach ($datas as $key => $value) {
                foreach ($value as $k => $v) {
                    if(!in_array($k,$arrarray)){
                        unset($datas[$key][$k]);
                    }
                }
            }
            foreach ($title as $key => $value) {
                if(!in_array($key,$arrarray)){
                    unset($title[$key]);
                }
            }
        } 
        $filename_n = time();
        $filename_exce = "sheet";
        // print_r($datas);die;
        // 生成Excel并返回文件名称
        $filename = ExportExcelTable($title,$datas,$filename_exce,$filename_n,'./Public/Uploads/ChannelCount/');
        $path = 'http://'.$_SERVER['SERVER_NAME'].substr($filename, 1, strlen($filename));
        $this -> ajaxReturn(['success'=>'OK','path' => $path], 'JSON');
        // exit(json_encode(['success'=>'OK','filename'=>$filename_n,'message'=>$filename_n.'导出成功！'])); 
    }


    public function get_d_m($status)
    {
        $time = [];
        if ($status == 1) {
            $y = date('Y', time());
            $y = $y - 1;
            for ($i = 1; $i<= 12; $i ++ ) {
                if($i<=9){
                    $times[] = $y.'-0'.$i;
                }else{
                    $times[] = $y.'-'.$i;
                }
            }
        } else if ($status == 2) {
            $y = date('Y', time());
            $m = date('m', time());
            if ($m <= 3) {
                $times = [$y.'-'.'01', $y.'-'.'02', $y.'-'.'03'];
            } else if ($m >= 4 && $m <=6) {
                $times = [$y.'-'.'04', $y.'-'.'05', $y.'-'.'06'];
            } else if ($m >=7 && $m <= 9) {
                $times = [$y.'-'.'07', $y.'-'.'08', $y.'-'.'09'];
            } else if ($m >= 10 && $m <= 12) {
                $times = [$y.'-'.'10', $y.'-'.'11', $y.'-'.'12'];
            }
        } else if ($status == 3) {
            $y = date('Y', time());
            $m = date('m', time());
            $m = $m - 1;
            if ($m <= 0) {
                $y = $y - 1;
                $m = 12;
            }
            $times = [$y.'-'.$m];
        } else if ($status == 4) {
            $y = date('Y', time());
            $m = date('m', time());
            $times = [$y.'-'.$m];
        } else if ($status == 5) {
            $orderM = D('order');
            $successTimes = session('successTimes');
            $overdueTimes = session('overdueTimes');
        }
        return $times;
    }
    public function  KefuGuoLv($data,$type){
        // print_r($data);die;
        if(!$data['waynum']){
            $data['waynum'] = "--";
        }

        if(!$data['contacts_name']){
            $data['contacts_name'] = "无";
        }
        if(!$data['contacts_bearing']){
            $data['contacts_bearing'] = "无";
        }
        if(!$data['contacts_phone']){
            $data['contacts_phone'] = "无";
        }
        if(!$data['contacts_user_name']){
            $data['contacts_user_name'] = "无";
        }
        if(!$data['contacts_sip_bearing']){
            $data['contacts_sip_bearing'] = "无";
        }
        if(!$data['contacts_phone_tel']){
            $data['contacts_phone_tel'] = "无";
        }

        if($data['income'] == "1"){
            $data['income'] = "10001以上";
        }else if($data['income'] == "2"){
            $data['income'] = "8001-10000";
        }else if($data['income'] == "3"){
            $data['income'] = "5001-8000";
        }else if($data['income'] == "4"){
            $data['income'] = "4001-5000";
        }else if($data['income'] == "5"){
            $data['income'] = "4001-5000";
        }else if($data['income'] == "6"){
            $data['income'] = "4001-5000";
        }else if($data['income'] == "7"){
            $data['income'] = "1001-2000";
        }else if($data['income'] == "8"){
            $data['income'] = "1000以下";
        }

        if($data['marriage'] == "1"){
            $data['marriage'] = "已婚有子女";
        }else if($data['marriage'] == "2"){
            $data['marriage'] = "已婚无子女";
        }else if($data['marriage'] == "3"){
            $data['marriage'] = "未婚";
        }else if($data['marriage'] == "4"){
            $data['marriage'] = "其他";
        }

        if($data['creditcard'] == "1"){
            $data['creditcard'] = "3张以下";
        }else if($data['creditcard'] == "2"){
            $data['creditcard'] = "3张以上";
        }

        if($data['borrowing'] == "1"){
            $data['borrowing'] = "无借款";
        }else if($data['borrowing'] == "2"){
            $data['borrowing'] = "有借款但已还清";
        }else if($data['borrowing'] == "3"){
            $data['borrowing'] = "有借款未还清";
        }

        if($data['housingnature'] == "1"){
            $data['housingnature'] = "自己有房";
        }else if($data['housingnature'] == "2"){
            $data['housingnature'] = "房屋按揭";
        }else if($data['housingnature'] == "3"){
            $data['housingnature'] = "租房住";
        }else if($data['housingnature'] == "4"){
            $data['housingnature'] = "和父母同住";
        }
        if($data['usertype'] == "0"){
            $data['usertype'] = "普通用户";
        }else if($data['usertype'] == "1"){
            $data['usertype'] = "职员,";
        }else if($data['usertype'] == "2"){
            $data['usertype'] = "副处级/公司副总/子公司总经理";
        }else if($data['usertype'] == "3"){
            $data['usertype'] = "副科级/部门负责人/副经理/子公司副总";
        }
        if($data['status'] == "0"){
          $data['status'] = "创建订单";
        }else if ($data['status'] == "2") {
          $data['status'] = "等待签约";
        }else if ($data['status'] == "3") {
          $data['status'] = "等待收款";
        }else if ($data['status'] == "4") {
          $data['status'] = "等待上牌";
        }else if ($data['status'] == "5") {
          $data['status'] = "等待提车";
        }else if ($data['status'] == "6") {
          $data['status'] = "已交付订单";
        }else if ($data['status'] == "-1") {
          $data['status'] = "拒单";
        }else if ($data['status'] == "-2") {
          $data['status'] = "订单驳回";
        }else if ($data['status'] == "7") {
          $data['status'] = "等待审核(风控经理)";
        }else if ($data['status'] == "1") {
          $data['status'] = "等待审核(城市经理)";  
        }
        $data["identify_url"]    =  $this->getPublicdianUrl($data["identify_url"],$type);
        $data["driver_url"]      =  $this->getPublicdianUrl($data["driver_url"],$type); 
        $data["workproof_url"]   =  $this->getPublicdianUrl($data["workproof_url"],$type);
        $data["bankflow_url"]    =  $this->getPublicdianUrl($data["bankflow_url"],$type);
        $data["creditreport_url"]=  $this->getPublicdianUrl($data["creditreport_url"],$type);
        $data["otherdata_url"]   =  $this->getPublicdianUrl($data["otherdata_url"],$type);
        return $data;
    }

    public function getPublicdianUrl($data,$type){
        if(!$type){
            $data =  serializeMysql($data,1);
        }
        $arr  = "";
        foreach ($data as $key => $value) {
          $res = substr($value,1);
          $arr .= C('OSSURL').$res."结束";
        }
        return $arr;
    }
}